package net.lcqf.udp;

import net.lcqf.udp.send.MessageFactory;
import net.lcqf.udp.server.UdpServer;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.*;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.FilterType;
import org.springframework.core.io.ClassPathResource;

/**
 * +----------------------------------------------------------------------
 * // | Talk To [ 聊来改善地区金融服务环境，助力企业发展 ]
 * // +----------------------------------------------------------------------
 * // | Copyright (c) 2021-2025 聊来 All rights reserved.
 * // +----------------------------------------------------------------------
 * // | Licensed ( <a href="http://www.apache.org/licenses/LICENSE-2.0">apache</a> )
 * // +----------------------------------------------------------------------
 * // | @Author: 聊来 <18970881148@qq.com>
 * // +----------------------------------------------------------------------
 * // | DateTime: 2025/2/12 14:18
 * // +----------------------------------------------------------------------
 */

@SpringBootApplication
@ComponentScan(basePackages = {
        "net.lcqf.udp.server",
        "net.lcqf.udp.send.message"
}, excludeFilters = {
        @ComponentScan.Filter(type = FilterType.ASSIGNABLE_TYPE, classes = {
                // 需要过滤的类
        })
}, basePackageClasses = {
        MessageFactory.class,
})  // 扫描项目需要用到的包

public class KcpApplication implements CommandLineRunner {

    @Value("${server.port}")
    private int port;

    private final UdpServer udpServer;

    public KcpApplication(UdpServer udpServer) { this.udpServer = udpServer;}

    public static void main(String[] args) {
        SpringApplication application = new SpringApplication(KcpApplication.class);
        application.setWebApplicationType(WebApplicationType.NONE);
        application.setBannerMode(Banner.Mode.CONSOLE);
        application.setBanner(new ResourceBanner(new ClassPathResource("banner.txt")));
        application.run(args);

        //SpringApplication.run(UdpApplication.class, args);
    }

    @Override
    public void run(String... args) throws Exception {
        udpServer.start(port);
    }
}
